<template>
	<view class="loginBox">
		<view class="loginTitle" style="">
			<view class="" style="width: 300rpx; height: 300rpx;">
				<image src="../../static/img/login.png" style="width: 100%;height: 100%;" mode=""></image>
			</view>
		</view>
		<!-- <u-toast ref="uToast" /> -->
		<view class="loginInput" style="padding: 0 20rpx;">
			<form>
				<u-form-item label="账号:"><u-input style="width: 85%;" id="zhanghao" type="" v-model="phone"
						:clearable='true' placeholder="请输入您的账号" /></u-form-item>
				<u-form-item label="密码:">
					<u-input style="width: 85%;" type="password" password-icon v-model="password"
						placeholder="请输入您的密码" />

				</u-form-item>
				<view class="forgetCode">
					<view class=""></view>
					<!-- <text @click="intoForgetCode">忘记密码?</text> -->
				</view>
			</form>
		</view>
		<view class="loginButton">
			<button type="primary" @click="login">登录</button>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		getUUID
	} from '../../utils/index.js'
	export default {
		data() {
			return {
				phone: "",
				password: "",
				show: false,
				area: '',
				typeShow: false,
			}
		},
		onShow() {
			this.phone = uni.getStorageSync('phone')
			this.password = uni.getStorageSync('password')
			// this.area = uni.getStorageSync('area')
		},
		onLoad() {
			this.phone = uni.getStorageSync('phone')
			this.password = uni.getStorageSync('password')
			// this.area = uni.getStorageSync('area')
			if (uni.getStorageSync('phone') && uni.getStorageSync('password')) {
				this.login()
			}
		},
		methods: {
			login() {
				console.log("点击了登录按钮");
				this.$u.post('/authorize/life/shop/user/small/program/login', {
					username: this.phone,
					password: this.password,
					uuid: getUUID(),
				}).then(res => {
					console.log(res)
					if(res.success){
						getApp().globalData.token = res.data.token
						getApp().globalData.userToken = res.data.userToken
						uni.setStorageSync('phone', this.phone)
						uni.setStorageSync('password',this.password)
						// console.log(getApp().globalData.token);
						// console.log(getApp().globalData.userToken);
						uni.switchTab({
							url:'/pages/tabBar/homePage',
						})
					}else{
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error',
						})
					}
				}).catch(() => {
					this.$refs.uToast.show({
						title: "请求失败",
						type: 'error',
					})
				})


			},
			intoForgetCode() {
				uni.navigateTo({
					url: '/pages/common/forgetCode'
				})
			}
			// getUserInfo(){
			// 	this.$u.get('api/getInfo', {
			// 	}).then(res => {
			// 		console.log(res);
			// 	})
			// }
		}
	}
</script>

<style scoped>
	page {
		background-color: #FFFFFF;
	}

	.loginBox {
		margin-left: 3%;
		margin-right: 3%;

	}

	.loginTitle {
		width: 100%;
		height: 400rpx;
		/* background-color: aquamarine; */
		font-size: 65px;
		display: flex;
		align-items: center;
		justify-content: space-around;
		color: #8C98AC;
	}

	.loginInput input {
		border-bottom: 1px solid #EAEAEA;
		margin-top: 50rpx;
	}

	.loginInput {
		/* background-color: red; */
	}

	.forgetCode {
		width: 75%;
		margin: 0 auto;
		color: red;
		font-size: 27rpx;
		margin-top: 60rpx;
		width: 100%;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.loginButton {
		margin-top: 150rpx;
	}

	.loginButton button {
		font-size: 13px;
		height: 100rpx;
		line-height: 100rpx;
		background-color: #31A7EA;
	}
</style>